<script setup>
import {reactive, ref} from "vue";
import request from "@/utils/request";
import {ElMessage} from "element-plus";
import router from "@/router";
import axios from "axios";

const user = reactive({
  form:{
    account: '',
    password: '',
    username: '',
    gender: '',
    age:0,
  },
});

const handleRegister = () => {
  console.log(user.form);
  axios.post('http://localhost:8080/auth/user/register', user.form).then((response)=>{
    console.log('response:',response.data);
    if(response.data.state === 2001){
      console.log(response.data);
      ElMessage.success('注册成功,快去登录吧');
      router.push("/login");
    }else {
      ElMessage.error('注册失败');
    }
  })
}

const handleReset = () => {
  user.form = {
    account: '',
    password: '',
    username: '',
    gender: '',
    age: 0,
  };
}

</script>
<template>
  <!-- 根容器 -->
  <div class="root">
    <!-- 登录容器，居中对齐 -->
    <div class="login-container">
      <div class="login-card">
        <el-header style="text-align: center;font-size: large">用户注册</el-header>
        <el-form :model="user.form" label-position="left" label-width="70px" class="elegant-form">
          <el-form-item label="账户名">
            <el-input v-model="user.form.account"/>
          </el-form-item>
          <el-form-item label="密码">
            <el-input v-model="user.form.password" show-password/>
          </el-form-item>
          <el-form-item label="真实姓名">
            <el-input v-model="user.form.username"/>
          </el-form-item>
          <el-form-item label="性别">
            <el-radio-group v-model="user.form.gender">
              <el-radio value="M">男</el-radio>
              <el-radio value="F">女</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="年龄">
            <el-input-number v-model="user.form.age" min="0"/>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" class="login-btn" @click="handleReset">重置</el-button>
            <el-button type="primary" class="login-btn" @click="handleRegister">立即注册</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<style scoped>
/* 根容器样式 */
.root {
  display: flex;
  min-height: 100vh;
  background: url("../assets/img/bg.jpg") no-repeat center/cover;
  backdrop-filter: blur(1px);
}

/* 登录容器样式 */
.login-container {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  padding-left: 10%;
}

/* 登录卡片样式 */
.login-card {
  width: 400px;
  min-height: 450px;
  background: rgba(30, 32, 36, 0.9);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(37, 37, 37, 0.3);
  backdrop-filter: blur(10px);
  border: 1px solid rgb(46, 45, 45);
  overflow: hidden;
  padding: 20px 0;
}

/* 透明tabs样式 */
.transparent-tabs {
  background: transparent !important;
  border: none !important;
}

/* tabs头部样式 */
::v-deep .transparent-tabs .el-tabs__header {
  background: rgba(37, 37, 37, 0.3);
  border-bottom: none;
  color: #2e2d2d;
}

/* 标签项字体颜色设为白色 */
::v-deep .transparent-tabs .el-tabs__item {
  color: rgba(255, 255, 255, 0.6); /* 更柔和的白色 */
  font-size: 16px;
  transition: all 0.3s ease-in-out;
}

/* 激活的标签项样式 */
::v-deep .transparent-tabs .el-tabs__item.is-active {
  color: #333333; /* 明显深色字体 */
  background-color: #ffffff; /* 白色背景 */
  font-weight: 500;
}

/* 标签项下划线颜色 */
::v-deep .transparent-tabs .el-tabs__nav-wrap::after {
  background-color: rgb(255, 255, 255);
}

/* 表单样式 */
.elegant-form {
  padding: 10px 25px 20px;
}

/* 表单项样式 */
.elegant-form .el-form-item {
  margin-bottom: 24px;
}

/* 最后一个表单项样式 */
.elegant-form .el-form-item:last-child {
  margin-bottom: 0;
}

/* 表单项标签字体颜色设为白色 */
.elegant-form ::v-deep .el-form-item__label {
  color: #ffffff;
}

/* 自定义输入框样式 */
.custom-input ::v-deep .el-input__inner {
  height: 42px;
  border-radius: 6px;
  border-color: #ffffff;
  transition: all 0.3s ease-in-out;
  box-sizing: border-box;
}

/* 聚焦时的输入框样式 */
.custom-input ::v-deep .el-input__inner:focus {
  border-color: rgba(37, 37, 37, 0.3);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6); /* 半透明外发光 */
}

.login-btn {
  width: 80px;
  height: 42px;
  font-size: 16px;
  letter-spacing: 2px;
  background: linear-gradient(45deg, rgb(133, 129, 129), rgba(37, 37, 37, 0.3));
  border: none;
  border-radius: 6px;
  transition: all 0.3s ease-in-out;
}

/* 鼠标悬停时的登录按钮样式 */
.login-btn:hover {
  opacity: 0.9;
  transform: translateY(-5px);
}

/* 底部链接样式 */
.footer-link {
  padding: 16px;
  text-align: right;
  font-size: 13px;
  color: #909399;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
}

/* 注册按钮样式 */
.register-btn {
  margin-left: 6px;
  font-size: 13px;
  color: #ffffff;
  transition: all 0.3s ease-in-out;
}

/* 鼠标悬停时的注册按钮样式 */
.register-btn:hover {
  color: #ffffff;
  text-decoration: underline;
}
</style>
